import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { viteMockServe } from "vite-plugin-mock";
export default defineConfig(({ command }) => {
  return {
    plugins: [
      vue(),
      //svg插件
      createSvgIconsPlugin({
        // Specify the icon folder to be cached
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        // Specify symbolid format
        symbolId: "icon-[dir]-[name]",
      }),
      //mock插件
      viteMockServe({
        mockPath: "mock",
        //保证开发阶段能够运行mock接口
        localEnabled: command === "serve",
      }),
    ],
    //设置@
    resolve: {
      alias: {
        "@": path.resolve("./src"),
      },
    },
    //打包设置
    build: {
      outDir: "dist",
      assetsDir: "assets",
      sourcemap: false,
      terserOptions: {
        compress: {
          drop_console: true,
          drop_debugger: true,
        },
      },
    },
    // 引入scss全局变量
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
  };
});
